package cn.learn.server.test;

import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ClientBase {

    protected static final File testBaseDir = new File(System.getProperty("build.test.dir", "build"));

    @Test
    public void testCreateEmptyDir() throws IOException {
        File file = ClientBase.createEmptyTestDir();
        String path = file.getAbsolutePath();
        System.out.println(path);
    }

    public static File createEmptyTestDir() throws IOException {
        return createTmpDir(testBaseDir, false);
    }

    static File createTmpDir(File parentDir, boolean createInitFile) throws IOException {
        if (!parentDir.exists()) {
            parentDir.mkdir();
        }
        File tmpFile = File.createTempFile("test", ".junit", parentDir);
        File tmpDir = new File(tmpFile + ".dir");
        assertFalse(tmpDir.exists());    // 判断目录是否存在，此处应该不存在
        assertTrue(tmpDir.mkdirs());    // 这里新建目录
        return tmpDir;
    }
}
